<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">

<title>管理员管理</title>
<!-- 引入easyui框架 -->
<link rel="stylesheet" type="text/css"
	href="../js/jquery-easyui-1.7.0/themes/default/easyui.css">
<link rel="stylesheet" type="text/css"
	href="../js/jquery-easyui-1.7.0/themes/icon.css">
<link rel="stylesheet" type="text/css"
	href="../js/jquery-easyui-1.7.0/themes/color.css">
<script type="text/javascript"
	src="../js/jquery-easyui-1.7.0/jquery.min.js"></script>
<script type="text/javascript"
	src="../js/jquery-easyui-1.7.0/jquery.easyui.min.js"></script>
</head>
<body>


	<!-- 设计一个数据表格用于列表显示管理员信息 -->
	<!-- 数据表格list  start  -->
	<table id="business_dg" title="管理员信息" class="easyui-datagrid"
		style="width: 100%; height: 600px" url="../sys/business/search"
		toolbar="#business_toolbar" pagination="true" rownumbers="true"
		fitColumns="true" fit="true" singleSelect="true">
		<thead>
			<tr>
				<th field="businessId" width="50">编号</th>
				<th field="businessName" width="50">商家</th>
				<th field="businessAddress" width="50">地址</th>
				<th field="businessExplain" width="50">信息</th>
				<th field="starPrice"   width="50">起配价格</th>
				<th field="deliveryPrice"   width="50">配送费</th>
			</tr>
		</thead>
	</table>
	<div id="business_toolbar">
		<a href="javascript:void(0)" class="easyui-linkbutton"
			iconCls="icon-add" plain="true" onclick="newFood()">新增</a> <a
			href="javascript:void(0)" class="easyui-linkbutton"
			iconCls="icon-edit" plain="true" onclick="editFood()">修改</a> <a
			href="javascript:void(0)" class="easyui-linkbutton"
			iconCls="icon-remove" plain="true" onclick="destroyFood()">删除</a>
	</div>
	<!-- 数据表格list  start  -->

	<!-- 数据新增对话框  start -->
	<div id="business_dlg" class="easyui-dialog"
		style="width: 400px; height: 280px; padding: 10px 20px" closed="true"
		buttons="#business_dlg-buttons">
		<div class="ftitle">管理员</div>
		<form id="business_fm" method="post">
			<div class="fitem">
				<label>管理员帐号:</label> <input name="adminName"
					class="easyui-validatebox" required="true">
			</div>

			<div class="fitem">
				<label>管理员密码:</label> <input name="password"
					class="easyui-passwordbox" required="true">
			</div>
			
			<div class="fitem">
				<label>角色:</label> <input name="roles" class="easyui-combobox"  data-options="url:'../sys/admin/rolelist', valueField:'id', textField:'roleName', multiple:true" required="true">
			</div>
			
			<div class="fitem">
				<label>头像:</label> <input name="file1"  class="easyui-filebox" >
			</div>

		</form>
	</div>
	<div id="business_dlg-buttons">
		<a href="#" class="easyui-linkbutton" iconCls="icon-ok"
			onclick="saveFood()">保存</a> <a href="#" class="easyui-linkbutton"
			iconCls="icon-cancel"
			onclick="javascript:$('#business_dlg').dialog('close')">取消</a>
	</div>

	<!-- 数据新增对话框  end -->


	<script type="text/javascript">
		function newFood() {
			//弹出新增对话框
			$('#business_dlg').dialog('open').dialog('setTitle', '新增管理员');
			//清空历史表单记录
			$('#business_fm').form('clear');
			//配置新增管理员的地址
			url = '../sys/admin/add';
		}

		function editFood() {
			//从数据表格中获取选定的要修改的一行数据
			var row = $('#business_dg').datagrid('getSelected');

			if (row) {
				$('#business_dlg').dialog('open').dialog('setTitle', '修改管理员');
				//把选择的数据填充会数据修改表单
				$('#business_fm').form('load', row);
				//api
				url = '../sys/admin/edit?adminId=' + row.adminId;
			} else {
				$.messager.show({
					title : 'Error',
					msg : '请选择一行数据'
				});
			}
		}

		function saveFood() {
			$('#business_fm').form('submit', {
				url : url,
				onSubmit : function() {
					return $(this).form('validate');
				},
				success : function(result) {
					var result = eval('(' + result + ')');
					if (result.errorMsg) {
						$.messager.show({
							title : 'Error',
							msg : result.errorMsg
						});
					} else {
						$.messager.show({
							title : 'Error',
							msg : "操作成功"
						});
						$('#business_dlg').dialog('close'); // close the dialog
						$('#business_dg').datagrid('reload'); // reload the user data
					}
				}
			});
		}

		function destroyFood() {
			var row = $('#business_dg').datagrid('getSelected');
			if (row) {
				$.messager.confirm('Confirm', '请确认删除管理员?', function(r) {
					if (r) {
						$.post('../sys/admin/del', {
							adminId : row.adminId
						}, function(result) {

							if (result.success) {
								$('#business_dg').datagrid('reload'); // reload the user data
							}

							$.messager.show({ // show error message
								title : 'Msg',
								msg : result.errorMsg
							});

						}, 'json');
					}
				});
			}else{
				$.messager.show({ // show error message
					title : 'Msg',
					msg : "请选择要删除的数据！"
				});	
			}
		}

		function showImage(value, row, index){
			return "<img height='50px' src='../"+value+"'></img>";
		}
		function showBusiness(value, row, index) {
			return value.businessName;
		}
		
	</script>

</body>
</html>